package com.zt.controller;

import com.zt.service.UserInfoService;
import com.zt.user.UserInfo;
import com.zt.utils.Result;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("user")
public class UserController {

    @Resource
    private UserInfoService userInfoService;


    //登录功能
    @GetMapping("login")
    public Result login(String username, String password, String code){
        return userInfoService.login(username, password, code);
    }


    //点击生成验证码
    @GetMapping("code")
    public Result code(){
        return userInfoService.code();
    }

    //获取当前登录用户
    @GetMapping("userinfo")
    public Result getUserInfo(){
        return userInfoService.getUserInfo();
    }

    //根据用户id查询用户
    @GetMapping("getUserById")
    public String getUserById(Integer uid){
        return userInfoService.getUserById(uid);
    }
//    查询用户信息
    @GetMapping("getUserInfoById")
    public UserInfo getUserInfoById(@RequestParam("userId") Integer userId){
        return userInfoService.getUserInfoById(userId);
    }
    //根据id查询用户信息
    @GetMapping("getUserId")
    public Result getUserId(Integer userId){
        return Result.success(userInfoService.getById(userId));
    }
    //查询用户名
    @GetMapping("ByName/{username}")
    public Result getUserByName(@PathVariable("username") String username){
        System.err.println("username = " + username);
        return userInfoService.getByName(username);
    }

    //    获取当前用户信息
    @GetMapping("getUserInfoUserId")
    public UserInfo getUserInfoUserId(){
        return userInfoService.getUserInfoUserId();
    }
    //    根据用户信息获取当前用户信息判断信息是否正确
//    @GetMapping("getUserInfoByUserInfo")
//    public Result getUserInfoByUserInfo(UserInfo userInfo){
//        return userInfoService.getUserInfoByUserInfo(userInfo);
//    }
    //    根据用户信息获取当前用户信息判断信息是否正确
    @GetMapping("getUserInfoByUserInfo")
    public UserInfo getUserInfoByUserInfo(@RequestParam("idCard") String idCard){
        return userInfoService.getUserInfoByUserInfo(idCard);
    }
}
